package com.itboye.mengwu.app.ui.mymeng;

import java.util.Observable;
import java.util.Observer;

import android.content.Intent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.widget.TextView;

import com.itboye.core.alert.ByAlert;
import com.itboye.core.object.BaseActivity;
import com.itboye.core.object.ResultEntity;
import com.itboye.core.object.SpPublicParams;
import com.itboye.core.utils.SPUtils;
import com.itboye.mengwu.R;
import com.itboye.mengwu.data.model.VIPPersonalBean;
import com.itboye.mengwu.data.presenter.ConfigAppPresenter;

public class ActivityMyBalance extends BaseActivity implements Observer {
	TextView txt_title;
	ImageView back;
	ImageView img_other;
	TextView mybalance;
	TextView tixian;
	TextView tixian_old;
	TextView bind_zhifubao;

	private String uid;

	private ConfigAppPresenter appPresenter;;
	private VIPPersonalBean vipPersonalBean;

	private String num;

	@Override
	public int initView() {
		// TODO Auto-generated method stub
		return R.layout.activity_mybalance;
	}

	@Override
	public void onMyCreate() {
		// TODO Auto-generated method stub

		showProgressDialog("数据加载中,请稍后", true);
		appPresenter = new ConfigAppPresenter(this);
		vipPersonalBean = new VIPPersonalBean();

		uid = SPUtils.get(ActivityMyBalance.this, null, SpPublicParams.UID, "")
				+ "";
		appPresenter.getGuanZhu(uid, "");

		txt_title.setText("我的余额");
		img_other.setVisibility(View.GONE);
		// mybalance.setText("￥123");
		back.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				finish();
			}
		});
		tixian.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				if (SPUtils.get(ActivityMyBalance.this, null,
						SpPublicParams.ALIPAY, "").equals("")) {
					ByAlert.alert("还未绑定支付宝哦");
					return;
				} else {
					Intent intent = new Intent(ActivityMyBalance.this,
							ApplyTiXianActivity.class);
					startActivity(intent);
				}

			}
		});
		/***
		 * 历史提现
		 */
		tixian_old.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				Intent intent = new Intent(ActivityMyBalance.this,
						HistoryWithdrawalsActivity.class);
				startActivity(intent);
			}
		});
		bind_zhifubao.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				Intent intent = new Intent(ActivityMyBalance.this,
						ActivityBindZhifubao.class);
				startActivity(intent);

			}
		});
	}

	@Override
	public void update(Observable observable, Object data) {
		// TODO Auto-generated method stub

		ResultEntity entity = handlerError(data);
		if (entity != null) {
			if (entity.getEventType() == ConfigAppPresenter.ConfigApp_success) {
				// ByAlert.alert(""+entity.getData());
			}
			if (entity.getEventType() == ConfigAppPresenter.Guanzhu_success) {
				vipPersonalBean = (VIPPersonalBean) entity.getData();
				num = vipPersonalBean.getBalance();
				mybalance.setText("￥" + num);

			}
		}

		try {
			closeProgressDialog();
		} catch (Exception e) {
			// TODO: handle exception
		}
	}

}
